﻿Imports System.Data.SqlClient
Public Class frmChungTuDs

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click

    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        If Me.dgvList.SelectedRows.Count > 0 Then
        Else
            MsgBox("Vui lòng chọn dòng cần Xóa!")
        End If
    End Sub

    Private Sub frmChungTuDs_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        UpdateList()
    End Sub

    Private Sub dgvList_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvList.CellDoubleClick
        MsgBox("test")
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        If Me.dgvList.SelectedRows.Count > 0 Then
            Dim frm As New frmChungTu(Me.dgvList.SelectedRows.Item(0).Cells(0).Value)
            frm.ShowDialog()
            If frm.booThanhCong = True Then
                UpdateList()
            End If
        Else
            MsgBox("Vui lòng chọn dòng cần Sửa!")
        End If
    End Sub

    Private Sub UpdateList()
        Dim strSql As String = "Select LoaiCT as [Loại chứng từ], TenCT as [Tên chứng từ], GhiChu as [Diễn giải] from ChungTu"
        Dim myConn As New SqlConnection(modKetNoi.strConnectionString)
        Dim myTable As New DataTable
        Try
            myConn.Open()
            Dim myAdapter As New SqlDataAdapter(strSql, myConn)
            myAdapter.Fill(myTable)
            dgvList.DataSource = myTable
            dgvList.Columns.Item(0).Width = 150
            dgvList.Columns.Item(1).Width = 250
            dgvList.Columns.Item(2).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
        Catch ex As Exception

        End Try
        myConn.Close()
        myConn.Dispose()
    End Sub
End Class